

class ActiveXContainer 
    : public IOleContainer
    , public IOleInPlaceFrame 
{ 
        internal ActiveXContainer(ActiveXHost* host)
        { 
            _host = host; 
        }

        // 
        // IOleContainer methods: 
        //
        int ParseDisplayName(Object pbc, string pszDisplayName, int[] pchEaten, Object[] ppmkOut) 
        {
            if (ppmkOut != null)
            {
                ppmkOut[0] = null;
            }
 
            return E_NOTIMPL;
        } 

        int EnumObjects(int grfFlags, IEnumUnknown ppenum)
        { 
            ppenum = null;
 
            object ax = _host.ActiveXInstance; 

            //We support only one control, return that here
            //How does one add multiple controls to a container?
            if (ax != null 
                &&
                ( ((grfFlags & OLECONTF_EMBEDDINGS) != 0) 
                  || 
                  ((grfFlags & OLECONTF_ONLYIFRUNNING) != 0 &&
                    _host.ActiveXState == ActiveXHelper.ActiveXState.Running )) ) 
            {
                Object[] temp = new Object[1];
                temp[0]= ax;
                ppenum = new EnumUnknown(temp); 
                return NativeMethods.S_OK;
            } 
 
            ppenum = new EnumUnknown(null);
            return NativeMethods.S_OK; 
        }

        int UnsafeNativeMethods.IOleContainer.LockContainer(bool fLock)
        { 
            return NativeMethods.E_NOTIMPL;
        } 
 
        //
        // IOleInPlaceFrame methods: 
        //
        // IOleInPlaceFrame methods
        virtual STDMETHODIMP GetBorder(LPRECT l);
        virtual STDMETHODIMP RequestBorderSpace(LPCBORDERWIDTHS);
        virtual STDMETHODIMP SetBorderSpace(LPCBORDERWIDTHS w);
        virtual STDMETHODIMP SetActiveObject(IOleInPlaceActiveObject*pV,LPCOLESTR s);
        virtual STDMETHODIMP InsertMenus(HMENU h,LPOLEMENUGROUPWIDTHS x);
        virtual STDMETHODIMP SetMenu(HMENU h,HOLEMENU hO,HWND hw);
        virtual STDMETHODIMP RemoveMenus(HMENU h);
        virtual STDMETHODIMP SetStatusText(LPCOLESTR t);
        virtual STDMETHODIMP EnableModeless(BOOL f);
        virtual STDMETHODIMP TranslateAccelerator(LPMSG,WORD);

        suic::Handle GetWindow()
        {
            return _host.GetParentHandle(); 
        }
 
        int UnsafeNativeMethods.IOleInPlaceFrame.ContextSensitiveHelp(int fEnterMode) 
        {
            return NativeMethods.S_OK; 
        }

        int UnsafeNativeMethods.IOleInPlaceFrame.GetBorder(NativeMethods.COMRECT lprectBorder)
        { 
            return NativeMethods.E_NOTIMPL;
        } 
 
        int UnsafeNativeMethods.IOleInPlaceFrame.RequestBorderSpace(NativeMethods.COMRECT pborderwidths)
        { 
            return NativeMethods.E_NOTIMPL;
        }

        int UnsafeNativeMethods.IOleInPlaceFrame.SetBorderSpace(NativeMethods.COMRECT pborderwidths) 
        {
            return NativeMethods.E_NOTIMPL; 
        } 

        int UnsafeNativeMethods.IOleInPlaceFrame.SetActiveObject(UnsafeNativeMethods.IOleInPlaceActiveObject pActiveObject, string pszObjName) 
        {
            return NativeMethods.S_OK; 
        }
 
        int UnsafeNativeMethods.IOleInPlaceFrame.InsertMenus(IntPtr hmenuShared, NativeMethods.tagOleMenuGroupWidths lpMenuWidths)
        {
            return NativeMethods.S_OK;
        } 

        int UnsafeNativeMethods.IOleInPlaceFrame.SetMenu(IntPtr hmenuShared, IntPtr holemenu, IntPtr hwndActiveObject) 
        { 
            return NativeMethods.E_NOTIMPL;
        } 

        int UnsafeNativeMethods.IOleInPlaceFrame.RemoveMenus(IntPtr hmenuShared)
        {
            return NativeMethods.E_NOTIMPL; 
        }
 
        int UnsafeNativeMethods.IOleInPlaceFrame.SetStatusText(string pszStatusText) 
        {
            return NativeMethods.E_NOTIMPL; 
        }

        int UnsafeNativeMethods.IOleInPlaceFrame.EnableModeless(bool fEnable)
        { 
            return NativeMethods.E_NOTIMPL;
        } 
 
        int UnsafeNativeMethods.IOleInPlaceFrame.TranslateAccelerator(ref MSG lpmsg, short wID)
        { 
            return NativeMethods.S_FALSE;
        }

        void OnUIActivate(ActiveXHost site)
        {
            if (_siteUIActive == site) 
                return;
 
            if (_siteUIActive != null )
            {
                ActiveXHost tempSite = _siteUIActive; 
                tempSite.ActiveXInPlaceObject.UIDeactivate(); 
            }

           _siteUIActive = site;

            //
        } 

        void OnUIDeactivate(ActiveXHost site)
        {
            _siteUIActive = null;
        } 
 
        void OnInPlaceDeactivate(ActiveXHost site)
        { 
            // 
            if (this.ActiveXHost == site)
            { 
            }
        }

        ActiveXHost* GetActiveXHost() const
        {
            return _host;
        }

        ActiveXHost* _host;
        ActiveXHost* _siteUIActive; 
    } 
}
